
const multer = require('koa-multer');

let fileName = "";

const storage = multer.diskStorage({

    //设置上传后文件路径，uploads文件夹会自动创建。
    destination: function (req, file, cb) {
        cb(null, './static/uploads/exel/')
    },

    //给上传文件重命名，获取添加后缀名
    filename: function (req, file, cb) {

        var fileFormat = (file.originalname).split(".");

        fileName = file.fieldname + '-' + Date.now() + "." + fileFormat[fileFormat.length - 1];
        cb(null, fileName);
    }

});


const upload = multer({
    storage: storage
});


module.exports= {
    post: {
        'file-upload': [upload.single('xlsx'), async (ctx, next) => {
            ctx.body = {
                code: 0,
                url: "uploads/exel/" + fileName
            };
            next();
        }]
    }
}